#include "shm.hpp"
#include "fifo_pipe.hpp"

int main(){
    Shm shm(PATH_NAME, PROJ_ID, CREATER);

    //使用管道来进行同步机制的模拟
    fifo_pipe fp(".", "fifo");
    fifo_operator fOpr(".", "fifo");
    fOpr.Open_to_read();
    
    char* receive = (char*)shm.Get_shm_addr();
    while(1){
        int rd = fOpr.Wait();
        if(rd < 0){
            ERR_EXIT("wait(read)");
            break;
        }
        else if(rd == 0){
            cout << "wait over!" << endl;
            break;
        }
        else printf("%s\n", receive);
        
    }

    struct shmid_ds pshmds = shm.get_shm_info();
    fOpr.Close();
    
    return 0;
}